<template>
  <el-dialog title="打印SN码" :visible.sync="showFlag" :modal="false" width="40%" @close="cancel">
    <div class="app-container" style="padding-top: 0px">
      <div class="contentDiv">
        <el-form
          ref="form"
          class="perForm"
          :model="caseInfo"
          label-width="120px"
          size="medium"
          :inline="true"
          style="margin-top: 20px"
        >
          <el-row :gutter="12">
            <el-form-item label="打印数量:" prop="electricPile">
              <el-input v-model="caseInfo.electricPile" type="number" :style="{ width: '200px' }" />
              <el-button type="primary" style="margin-left: 20px;" @click="getelectricPile">定制车载条码1</el-button>
            </el-form-item>
          </el-row>

          <el-row :gutter="12">
            <el-form-item label="打印数量:" prop="vehicle">
              <el-input v-model="caseInfo.vehicle" type="number" :style="{ width: '200px' }" />
              <el-button type="primary" style="margin-left: 20px;" @click="getVehicle">定制车载条码2</el-button>
            </el-form-item>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: right;">
          <el-button type="primary" @click="cancel">取 消</el-button>
        </div>
      </div>
    </div>
  </el-dialog>
</template>
        
    <script>
// reportAll
import { electricPile, vehicle } from "@/api/mes/pro/workorderSn";
export default {
  name: "productReport",
  data() {
    return {
      caseInfo: {},
      showFlag: false,
      snList: []
    };
  },
  methods: {
    init(row) {
      console.log(row, "row");
      this.snList = row;
      // this.caseInfo.reportSn = row.snCode;
      // this.caseInfo.snId = row.snId;
      this.showFlag = true;
    },
    //车载1的打印功能
    getelectricPile() {
      let param = {
        snCode: this.caseInfo.reportSn,
        number: this.caseInfo.electricPile
      };
      let list = []
      this.snList.map((item, index) => {
        list.push(
          Object.assign({}, {
            snCode: item.snCode,
            number: this.caseInfo.electricPile,
            productSpec:item.productSpec
          })
        );
      });
      console.log(list,"====list====");
      electricPile(list).then(res => {
        this.$message.success(res);
        //清空表单
        // this.caseInfo = {}
        // if(res.code == 200){
        //   this.showFlag = false;
        // }
      });
    },
    //车载2的打印功能
    getVehicle() {
      let param = {
        snCode: this.caseInfo.reportSn,
        number: this.caseInfo.vehicle
      };
      let list = []
      this.snList.map((item, index) => {
        list.push(
          Object.assign({}, {
            snCode: item.snCode,
            number: this.caseInfo.vehicle,
            productSpec:item.productSpec
          })
        );
      });
      vehicle(list).then(res => {
        this.$message.success(res);
        //清空表单
        // this.caseInfo = {}
        // if(res.code == 200){
        //   this.showFlag = false;
        // }
      });
    },
    //确定
    confirmSelect() {
      let param = {
        snCode: this.caseInfo.snCode,
        snId: this.caseInfo.snId
      };
      replaceSn(param).then(res => {
        if (res.code == 200) {
          this.$message.success(res.msg);
          //清空表单
          this.caseInfo = {};
          this.showFlag = false;
          this.$parent.getList();
        }
      });
    },
    cancel() {
      this.caseInfo = {};
      this.showFlag = false;
    }
  }
};
</script>
        <style lang="scss" scoped>
// .contentDiv {
//   width: 1350px;
// }
.el-table {
  margin-bottom: 15px;
}
</style>